package com.example.service.impl;

import com.example.controller.ClazzController;
import com.example.mapper.ClazzMapper;
import com.example.pojo.Clazz;
import com.example.pojo.PageResult;
import com.example.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ClazzServiceimpl implements ClazzService {
    @Autowired
    private ClazzMapper clazzMapper;
    //查询所有班级
    @Override
    public List<Clazz> findAll() {
        List<Clazz> clazzList = clazzMapper.findAll();
        return clazzList;
    }
    //新增班级
    @Override
    public void save(Clazz clazz) {
        clazz.setCreateTime(LocalDateTime.now());
        clazz.setUpdateTime(LocalDateTime.now());
        clazzMapper.save(clazz);
    }
    //分页查询班级
    @Override
    public PageResult findPage(Integer page, Integer pageSize) {
        Long total = clazzMapper.count();
        Integer start = (page-1)*pageSize;
        List<Clazz> rows = clazzMapper.list(start,pageSize);

        return new PageResult(total,rows);
    }
    //删除班级
    @Override
    public void delete(Integer id) {
        clazzMapper.delete(id);
    }
    //根据ID查询班级
    @Override
    public Clazz getById(Integer id) {
        Clazz clazz = clazzMapper.getById(id);
        return clazz;
    }
    //修改班级
    @Override
    public void update(Clazz clazz) {
        clazz.setCreateTime(LocalDateTime.now());
        clazz.setUpdateTime(LocalDateTime.now());
        clazzMapper.update(clazz);
    }
}
